package com.xjh.t.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjh.t.common.DataGridView;
import com.xjh.t.common.ResultObj;
import com.xjh.t.domain.ClassLevel;
import com.xjh.t.domain.EnglishExamination;
import com.xjh.t.service.IEnglishExaminationService;
import com.xjh.t.service.IEnglishWordService;
import com.xjh.t.vo.ClassLevelVo;
import com.xjh.t.vo.ExaminationVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author satela
 * @since 2025-09-23
 */
@RestController
@RequestMapping("/english-examination")
public class EnglishExaminationController {

    @Autowired
    private IEnglishExaminationService englishExaminationService;


    @RequestMapping("/loadAllExamination")
    public DataGridView loadAllExamination(ExaminationVo examinationVo) {

        IPage<EnglishExamination> page=new Page<>(examinationVo.getPage(), examinationVo.getLimit());
        QueryWrapper<EnglishExamination> queryWrapper=new QueryWrapper<>();

        queryWrapper.like(StringUtils.isNotBlank(examinationVo.getTitle()), "title",examinationVo.getTitle());
        queryWrapper.eq(examinationVo.getLevel() != null && examinationVo.getLevel() < 11, "level",examinationVo.getLevel());
        queryWrapper.eq(examinationVo.getType() != null && examinationVo.getType() < 3, "type",examinationVo.getType());

        queryWrapper.eq(examinationVo.getHasAnswer() != null, "has_answer",examinationVo.getHasAnswer());
        queryWrapper.orderByDesc("upload_time");

        this.englishExaminationService.page(page, queryWrapper);



        return new DataGridView(page.getTotal(),page.getRecords());

    }

    @RequestMapping("/addExamination")
    public ResultObj addExamination(EnglishExamination englishExamination,@RequestParam("files") MultipartFile[] srcFile) {

        QueryWrapper<EnglishExamination> queryWrapper = new QueryWrapper<>();


        englishExamination.setUploadTime(new Date());
        this.englishExaminationService.save(englishExamination);

        return ResultObj.ADD_SUCESS;

    }

}

